#pragma once

#include <QWidget>
#include "ui_ExD3DWidget.h"

#include <string>

#include "ExType.h"
#include "ExMacro.h"


class ExD3DWidget : public QWidget
{
	Q_OBJECT

public:

	ExD3DWidget(QWidget *parent = Q_NULLPTR);
	~ExD3DWidget();

	virtual bool InitDirect3D();

	virtual void OnResize();

	ID3D11Device* GetD3dDevice();

	ID3D11DeviceContext* GetD3dImmediateContext();

	IDXGISwapChain* GetSwapChain();

	ID3D11RenderTargetView* GetRenderTargetView();

	ID3D11DepthStencilView* GetDepthStencilView();

protected:

	// Direct3D 11
	ComPtr<ID3D11Device> D3dDevice;                    // D3D11设备
	ComPtr<ID3D11DeviceContext> D3dImmediateContext;   // D3D11设备上下文
	ComPtr<IDXGISwapChain> D3dSwapChain;                  // D3D11交换链
	// Direct3D 11.1
	ComPtr<ID3D11Device1> D3dDevice1;                  // D3D11.1设备
	ComPtr<ID3D11DeviceContext1> D3dImmediateContext1; // D3D11.1设备上下文
	ComPtr<IDXGISwapChain1> D3dSwapChain1;                // D3D11.1交换链
	// 常用资源
	ComPtr<ID3D11Texture2D> DepthStencilBuffer;        // 深度模板缓冲区
	ComPtr<ID3D11RenderTargetView> RenderTargetView;   // 渲染目标视图
	ComPtr<ID3D11DepthStencilView> DepthStencilView;   // 深度模板视图
	D3D11_VIEWPORT ScreenViewport;                      // 视口

	UINT MsaaQulity;    // MSAA支持的质量等级
	bool Enable4xMsaa;   //是否开启4倍多重采样？

private:

	QPaintEngine* paintEngine() const { return nullptr; }	// 允许dx渲染, 不重写这个会闪烁

private:

	Ui::ExD3DWidget ui;
};
